<template>
  <section>
    <div>
      <!-- 音频标签，但不在模板中显示按钮 -->
      <audio ref="audioPlayer" :src="audioSource" autoplay></audio>
    </div>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;text-align: center">
      <el-form :inline="true" :model="query">
<!--        <el-form-item>-->
<!--          <el-button type="primary" @click="newOrder" plain>刷新</el-button>-->
<!--        </el-form-item>-->
        <el-form-item style="float:left">
          <el-input v-model="query.keyword" placeholder="订单号" style="width:200px" clearable></el-input>
          <el-button type="primary" v-on:click="search" style="margin-left: 5px;">查询</el-button>
        </el-form-item>


        <el-select v-model="selectOption" clearable placeholder="商品类型" @change="selectChange" style="width: 120px; height: 40px;margin-right: 10px;"  >
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            {{ item.label }}
          </el-option>
        </el-select>

        <el-select v-model="selectOtype" clearable placeholder="订单状态" @change="selectChangeOne" style="width: 120px; height: 40px;margin-right: 10px;" >
          <el-option
              v-for="item in Otypes"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            {{ item.label }}
          </el-option>
        </el-select>
        <el-form-item style="margin-right: 10px;">
          <el-button type="primary" @click="receiving" plain>批量接单</el-button>
        </el-form-item>

        <el-form-item style="margin-right: 10px;">
          <el-button type="primary" @click="loadRefundOrderByIds" plain>批量退款</el-button>
        </el-form-item>
        <el-date-picker
            v-model="time"
            type="date"
            style="width: 140px; height: 40px;margin-right: 10px;"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            @change="loadRefundOrderByTime"
            placeholder="选择日期">
        </el-date-picker>
        <el-form-item style="margin-left: 10px;">
          <el-button type="primary" @click="getCopys" plain>批量复制</el-button>
        </el-form-item>
        <el-form-item style="margin-right: 10px;">
          <el-button type="primary" size="small" @click="getCompleteByOid" round>完成度校验</el-button>
        </el-form-item>
        <el-form-item style="float: left">
          <el-input v-model="query.url" placeholder="URL链接" style="width: 200px;" clearable></el-input>
          <el-button type="primary" plain @click="search" style="margin-left: 5px;">查询</el-button>
          <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0" style="margin-left: 40px;">删除订单记录</el-button>
<!--          <el-button type="danger" @click="deleteByDate"  style="margin-left: 8px;">日期删除</el-button>-->
        </el-form-item>

      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="pageInfo.rows" highlight-current-row v-loading="listLoading" @selection-change="selsChange"
              style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="goods.name" label="商品" width="80" sortable>
      </el-table-column>
      <el-table-column prop="manager.username" label="商家" width="80" sortable>
      </el-table-column>
      <el-table-column prop="goods" label="初始数据" width="200" sortable>
        <template slot-scope="scope">
          <span v-if="scope.row.goods.type == 1">关注:{{ scope.row.sFollow }}</span>
          <span v-if="scope.row.goods.type == 2">转发:{{ scope.row.sForward }}</span>
          <span v-if="scope.row.goods.type == 3">评论:{{ scope.row.sComment }}</span>
          <span v-if="scope.row.goods.type == 4">点赞:{{ scope.row.sGood }}</span>
          <span v-if="scope.row.goods.type == 6">视频播放:{{scope.row.sVideo}}</span>
          <span v-if="scope.row.goods.type == 5">阅读:{{ scope.row.sFollow }}</span>
          <span v-if="scope.row.goods.type == 7">点赞:{{ scope.row.sGood }}，评论:{{ scope.row.sComment }}，转发:{{ scope.row.sForward }}</span>
          <span v-if="scope.row.goods.type == 8 && scope.row.sType==2 ">转发:{{ scope.row.sForward }}</span>
          <span v-if="scope.row.goods.type == 8 && scope.row.sType==3 ">评论:{{ scope.row.sComment }}</span>
          <span v-if="scope.row.goods.type == 8 && scope.row.sType==4 ">点赞:{{ scope.row.sGood }}</span>
          <span v-if="scope.row.goods.type == 9">评中评:{{ scope.row.sComment }},UID:{{scope.row.refundNumber}}</span>
          <span v-if="scope.row.goods.type == 10">评论赞:{{ scope.row.sGood }}</span>

        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="100" sortable>
      </el-table-column>
      <el-table-column prop="oType" label="订单状态" width="100" sortable>
        <template slot-scope="scope">
          <span v-if="scope.row.oType === 7" style="color: red;">待处理</span>
          <span v-if="scope.row.oType === 1" style="color: black;">待接单</span>
          <span v-if="scope.row.oType === 2" style="color: green;">进行中</span>
          <span v-if="scope.row.oType === 3" style="color: green;">已完成</span>
          <span v-if="scope.row.oType === 4" style="color: red;">订单取消</span>
          <span v-if="scope.row.oType === 5" style="color: darkred;">退款中</span>
          <span v-if="scope.row.oType === 6" style="color: red;">已完成，无权限查看</span>
          <span v-if="scope.row.oType === 9" style="color: red;">订单异常退款</span>
        </template>
      </el-table-column>
      <el-table-column prop="user.username" label="用户" width="100" sortable>
      </el-table-column>
      <el-table-column prop="Completion" label="完成数量" width="100" sortable>
        <template slot-scope="scope">
          <span v-if="scope.row.goods.type == 1">关注:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 2">转发:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 3">评论:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 4">点赞:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 6">视频播放:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 5">阅读:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 7">转发:{{ scope.row.completionSf }}，评论:{{ scope.row.completionSc }}，点赞:{{ scope.row.completionSg }}</span>
          <span v-if="scope.row.goods.type == 8">{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 9">评中评:{{ scope.row.Completion }}</span>
          <span v-if="scope.row.goods.type == 10">评论赞:{{ scope.row.Completion }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="surplus" label="剩余量" width="100" sortable>
        <template slot-scope="scope">
          <span v-if="scope.row.goods.type == 1">关注:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 2">转发:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 3">评论:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 4">点赞:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 6">视频播放:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 5">阅读:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 7">转发:{{ scope.row.surplusSf }}，评论:{{ scope.row.surplusSc}}，点赞:{{ scope.row.surplusSg}}</span>
          <span v-if="scope.row.goods.type == 8">{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 9">评中评:{{ scope.row.surplus }}</span>
          <span v-if="scope.row.goods.type == 10">评论赞:{{ scope.row.surplus }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="oId" label="订单号" width="100" sortable>
      </el-table-column>
      <el-table-column prop="url" label="微博链接" width="180" sortable>
      </el-table-column>
      <el-table-column prop="count" label="订单数量" width="100" sortable>
      </el-table-column>
      <el-table-column prop="finalPrice" label="订单总价" width="100" sortable>
      </el-table-column>
      <!--      <el-table-column prop="weiboUsername" label="微博用户名" width="100" sortable>-->
      <!--      </el-table-column>-->
      <el-table-column label="操作" fixed="right" width="120">
        <template scope="scope">
          <el-button type="danger" @click="refund(scope.$index, scope.row)" v-if="scope.row.oType ===1">确认退款
          </el-button>
          <el-button type="primary" @click="receiv(scope.$index, scope.row)" v-if="scope.row.oType === 1">接单
          </el-button>
          <el-button type="success" @click="getCopy(scope.row.id)">复制
          </el-button>
<!--          <el-button type="primary" @click="getDeduction(scope.$index, scope.row)">手动扣款-->
<!--          </el-button>-->
          <el-button type="primary" @click="getCompleteByOrder(scope.row.id)" v-if="scope.row.oType === 2">订单完成
          </el-button>
          <!--          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">

      <!--      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>-->
      <!--      @size-change 当每页显示条数的值发生改变时会触发-->
      <!--      @current-change 当 当前页的值发生改变时会触发-->
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[80, 100, 120, 140]"
          :page-size="query.pageSize" layout="total, sizes, prev, pager, next, jumper"
          :total="pageInfo.total"
          :current-page="query.currentPage"
          style="float: right">
      </el-pagination>
    </el-col>



    <el-dialog title="完成度校验" :visible.sync="CompleteVisible"  width="1500">
      <el-input v-model="completeByOid" placeholder="请输入订单号" style="width: 350px;"></el-input>
      <el-button type="primary" @click="completeOid">查询订单</el-button>
      <el-table :data="completeData">
        <el-table-column prop="" label="原数据" width="30">
        </el-table-column>
        <el-table-column prop="url" label="微博链接" width="300">
        </el-table-column>
        <el-table-column prop="goods" label="初始数据" width="150" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.goods.type == 1">关注:{{ scope.row.sFollow }}</span>
            <span v-if="scope.row.goods.type == 2">转发:{{ scope.row.sForward }}</span>
            <span v-if="scope.row.goods.type == 3">评论:{{ scope.row.sComment }}</span>
            <span v-if="scope.row.goods.type == 4">点赞:{{ scope.row.sGood }}</span>
            <span v-if="scope.row.goods.type == 6">视频播放:{{scope.row.sVideo}}</span>
            <span v-if="scope.row.goods.type == 7">点赞:{{ scope.row.sGood }}，评论:{{ scope.row.sComment }}，转发:{{ scope.row.sForward }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="Completion" label="完成数量" width="80" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.goods.type == 1">关注:{{ scope.row.Completion }}</span>
            <span v-if="scope.row.goods.type == 2">转发:{{ scope.row.Completion }}</span>
            <span v-if="scope.row.goods.type == 3">评论:{{ scope.row.Completion }}</span>
            <span v-if="scope.row.goods.type == 4">点赞:{{ scope.row.Completion }}</span>
            <span v-if="scope.row.goods.type == 6">视频播放:{{ scope.row.Completion }}</span>
            <!--          <span v-if="scope.row.goods.type == 5">阅读</span>-->
            <span v-if="scope.row.goods.type == 7">转发:{{ scope.row.completionSf }}，评论:{{ scope.row.completionSc }}，点赞:{{ scope.row.completionSg }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="surplus" label="剩余量" width="80" sortable>
          <template slot-scope="scope">
            <span v-if="scope.row.goods.type == 1">关注:{{ scope.row.surplus }}</span>
            <span v-if="scope.row.goods.type == 2">转发:{{ scope.row.surplus }}</span>
            <span v-if="scope.row.goods.type == 3">评论:{{ scope.row.surplus }}</span>
            <span v-if="scope.row.goods.type == 4">点赞:{{ scope.row.surplus }}</span>
            <span v-if="scope.row.goods.type == 4">视频播放:{{ scope.row.surplus }}</span>
            <!--          <span v-if="scope.row.goods.type == 5">阅读</span>-->
            <span v-if="scope.row.goods.type == 7">转发:{{ scope.row.surplusSf }}，评论:{{ scope.row.surplusSc}}，点赞:{{ scope.row.surplusSg}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="count" label="总量" width="80">
        </el-table-column>
        <!--             <el-table-column prop="commentUrl" label="微博评论链接" width="300" >-->
        <!--             </el-table-column>-->
      </el-table>
<!--      <el-input v-model="veurl.url" placeholder="请输入微博URL" style="width: 350px;"></el-input>-->
      <el-button type="primary" @click="ve">URL校验</el-button>
      <el-table :data="veData">
        <el-table-column prop="" label="新数据" width="30">
        </el-table-column>
        <el-table-column prop="sFollow" label="关注/粉丝" width="100">
        </el-table-column>
        <el-table-column prop="sForward" label="转发" width="100">
        </el-table-column>
        <el-table-column prop="sComment" label="评论" width="100">
        </el-table-column>
        <el-table-column prop="sGood" label="点赞" width="100">
        </el-table-column>
        <el-table-column prop="sVideo" label="视频播放" width="100">
        </el-table-column>

        <!--             <el-table-column prop="commentUrl" label="微博评论链接" width="300" >-->
        <!--             </el-table-column>-->
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="refreshByOid">更新数据</el-button>
        <el-button @click.native="CompleteVisible = false">取消</el-button>
        <!--            <el-button type="primary" @click.native="save" :loading="addLoading">提交</el-button>-->
      </div>
    </el-dialog>

    <!--复制界面-->
    <el-dialog title="复制" :visible.sync="saveFormVisible" :close-on-click-modal="false" width="1500">
      <el-table :data="listData" v-loading="Loading">
        <el-table-column prop="str" label="复制" width="700" >
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="copy">一键复制</el-button>
        <el-button @click.native="saveFormVisible = false">取消</el-button>
        <!--            <el-button type="primary" @click.native="save" :loading="addLoading">提交</el-button>-->
      </div>
    </el-dialog>


    <!--日期删除界面-->
    <el-dialog title="根据日期删除" :visible.sync="deleteFormVisible" :close-on-click-modal="false" width="1500">
      <el-date-picker
          v-model="DeleteDto.time"
          type="date"
          style="width: 140px; height: 40px;margin-right: 10px;"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          @change=""
          placeholder="选择日期">
      </el-date-picker>
      <div slot="footer" class="dialog-footer">
        <el-button type="danger" @click="deleteBytime">确定删除</el-button>
        <el-button @click.native="deleteFormVisible = false">取消</el-button>
        <!--            <el-button type="primary" @click.native="save" :loading="addLoading">提交</el-button>-->
      </div>
    </el-dialog>

    <!--退款界面-->
    <el-dialog title="退款" :visible.sync="refundFormVisible" :close-on-click-modal="false" width="1500">
      <div>
        <el-input-number v-model="input"  :min="0" :max="10000000" label="描述文字">请输入退款数量</el-input-number>
        <el-button type="primary" @click="confirmRefund">退款</el-button>
      </div>

    </el-dialog>

    <!-- 批量退款界面 -->
    <el-dialog title="批量退款界面" :visible.sync="bulkRefundVisible" :close-on-click-modal="false">
      <el-table :data="bulkRefundData">
        <el-table-column prop="id" label="订单id" width="90" sortable>
        </el-table-column>
        <el-table-column prop="oId" label="订单号" width="100" sortable>
        </el-table-column>
        <el-table-column prop="count" label="订单数量" width="100" sortable>
        </el-table-column>
        <el-table-column prop="Completion" label="完成数量" width="100" sortable>
        </el-table-column>
        <el-table-column prop="surplus" label="剩余量" width="90" sortable>
        </el-table-column>
        <el-table-column prop="finalPrice" label="订单总价" width="100" sortable>
        </el-table-column>
        <el-table-column prop="weiboUsername" label="完成单量" width="110" sortable>
          <template slot-scope="scope">
            <el-input
                v-model="scope.row.Completion"
                min="1"
                maxlength="12"
                placeholder="请输入你已完成的单量">
            </el-input>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="bulkRefund">确认退款</el-button>
        <el-button @click.native="bulkRefundVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import {number} from "echarts/lib/export";
export default {
  computed: {
    number() {
      return number
    }
  },
  data() {
    return {
      CompleteVisible:false,
      completeData:[],
      veData:[],
        // surplus:'',
        // sGood: '',
        // sForward: '',
        // sComment: '',
        // Completion:'',
        // count:''

      Loading:false,

      audioSource: 'http://webshoppingfour.com//pic/order.mp3', // 本地音频文件路径
      isPlaying:false,
      intervalId1:null,
      intervalId2:null,
      intervalId: null,
      input:'',
      // 查看当前登录人
      loginAccount: '',
      listData: [],
      pageInfo: {
        rows: [],
        total: 0
      },
      selectOption: '',
      selectOtype: '',

      listLoading: false,
      sels: [],//列表选中列
      saveFormVisible: false,//新增界面是否显示
      deleteFormVisible:false,
      refundFormVisible:false,
      completeByOid:'',
      addLoading: false,
      saveFormRules: {},

      merchantRefund:{
        oid:'',
        num:'',
      },

      newOrderDto:{
        total:'',
        shopId:'',
      },
      veurl:{
        url:''
      },
      query: {
        currentPage: 1,
        pageSize: 80,
        keyword: "",
        accountId: '',
        gtype: '',
        otype: '',
        type: '',
        createTime:'',
        url:'',

      },
      time: null,
      DeleteDto: {
        time:null,
        accountId:'',
      },
      options: [{
        value: '1',
        label: '关注'
      }, {
        value: '2',
        label: '转发'
      }, {
        value: '3',
        label: '评论'
      }, {
        value: '4',
        label: '点赞'
      }, {
        value: '5',
        label: '阅读'
      },
        {
          value: '6',
          label: '视频播放'
        },
        {
          value: '7',
          label: '真人转评赞'
        },
        {
          value: '8',
          label: '统一转评赞'
        },
        {
          value: '9',
          label: '评中评'
        },
        {
          value: '10',
          label: '评论赞'
        }],


      Otypes: [
        {
          value: '7',
          label: '待处理'
        },{
        value: '1',
        label: '待接单'
      }, {
        value: '2',
        label: '进行中'
      }, {
        value: '3',
        label: '已完成'
      }, {
        value: '4',
        label: '订单取消'
      },
        {
          value: '5',
          label: '退款中'
        }, {
          value: '6',
          label: '无权限'
        }, {
          value: '9',
          label: '订单异常退款'
        }],

      //复制界面数据
      saveForm: {
        Url: '',
        type: "",
        count: ""
      },

      // 批量退款弹窗
      bulkRefundVisible: false,
      // 装批量退单的数据
      bulkRefundData: [],

    }
  },
  methods: {
    deleteByDate(){
      this.deleteFormVisible = true;
    },
    deleteBytime(){
      this.deleteFormVisible = false;
      this.DeleteDto.accountId = this.query.accountId;
      this.$http.post("/order/deleteBytime",this.DeleteDto)
            .then(result => {
              result = result.data;
              if (result.success) {
                this.getOrder();
                this.$message({message: result.message, type: 'success'});
              } else {
                this.$message({message: result.message, type: 'error'});
              }
            })

    },

    refreshByForward(){
      // 获取选中的行
      if (!this.sels || this.sels.length < 1) {
        this.$message({message: '老铁，你未选中数据', type: 'error'});
        return;
      }
      this.$confirm('确认获取特殊URL初始数据？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        this.$http.post('/order/refreshByForward', this.sels).then((result) => {
          this.listLoading = false;
          result = result.data;
          if (result.success) {
            this.$message({
              message: result.message,
              type: 'success'
            });
          } else {
            this.$message({
              message: result.message,
              type: 'error'
            });
          }
          this.getOrder();
        });
      }).catch(() => {

      });
    },


    refreshByOid(){
      this.$http.get("/order/refreshByOid/"+ this.completeByOid)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              this.CompleteVisible = false;
              this.completeData = null;
              this.completeByOid = null;
              this.veData = null;
              // console.log('===========')
              // console.log(this.veData)
              this.$message({message: result.message, type: 'success'});
            } else {
              this.$message({message: result.message, type: 'error'});
            }
            this.getOrder();
          })

    },


    ve(){
      this.$http.get("/order/verification/"+ this.completeByOid)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              this.veData = result.resultObj;
              // console.log(this.veData);
              // console.log('=======')
              this.$message({message: result.message, type: 'success'});
            } else {
              this.$message({message: result.message, type: 'error'});
            }
            this.getOrder();
          })

    },

    completeOid(){
      this.$http.get("/order/completeOid/"+ this.completeByOid)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              this.completeData = result.resultObj;
              // this.veData = this.completeData;

              // console.log('----------------')
              // console.log(this.completeData)
              // console.log('===========')
              // console.log(this.veData)
              this.$message({message: "查询成功", type: 'success'});
            } else {
              this.$message({message: result.message, type: 'error'});
            }
            this.getOrder();
          })
    },
    getCompleteByOid(){
      this.CompleteVisible =true
    },

    playAudio() {
      const audioPlayer = this.$refs.audioPlayer;
      if (audioPlayer.paused || audioPlayer.currentTime <= 0) {
        audioPlayer.play();
      }
    },
    //语音播报




  // 批量退款
    bulkRefund(){
      let orderIds = [];
      this.bulkRefundData.map(item =>{
        if (item.refundNumber > item.count){
          orderIds.push(item.id)
        }
      })
      if (orderIds.length > 0){
        this.$message({message: '订单 id 为：' + orderIds + ' 的订单输入的完成数量大于订单量，请重新输入!', type: 'error'});
        return;
      }
      // 调后端接口退款
      this.$http.post("/order/bulkRefund", this.bulkRefundData)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              this.bulkRefundVisible = false;
              this.$message({message: "批量退款成功", type: 'success'});
            } else {
              this.$message({message: result.message, type: 'error'});
            }
            this.getOrder();
          })

    },
    loadRefundOrderByTime(){
      // console.log(this.time)
      this.query.createTime = this.time;
      this.getOrder();
    },

    // 获取批量退款订单
    loadRefundOrderByIds(){
      let state = 0;

      var ids = this.sels.map(item => item.id);
      // 获取选中的行
      if (!this.sels || this.sels.length < 1) {
        this.$message({message: '老铁，你未选中数据', type: 'error'});
        return;
      }
      this.sels.map(item =>{
        if (item.oType == 4){
          state = state + 1
        }
      })
      if (state > 0){
        this.$message({message: '你选中订单有已取消的订单，请重新选择', type: 'error'});
        return;
      }
      // 调后端接口获取退款订单
      this.$http.post("/order/loadByIds", ids)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              this.bulkRefundVisible = true;
              this.bulkRefundData = result.resultObj;
              // console.log(this.bulkRefundData)

              this.bulkRefundData.map(item =>item.refundNumber=0)
            } else {
              this.$message({message: result.message, type: 'error'});
            }
          })
    },

    getOrderTotal(){
      this.newOrderDto.shopId=this.query.accountId;
      this.$http.get("/order/GetOrderTotal/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // this.$message({message: result.message, type: 'success'});
              // this.getOrder();
              this.newOrderDto.total = result.resultObj;
            } else {
              this.$message({message: result.message, type: 'error'});
            }
          });
    },

    newOrder(){
      this.$http.post("/order/newOrder" , this.newOrderDto)
          .then(result => {
            result = result.data;
            if (result.success) {
              this.$message({message: result.message, type: 'success'});
              // alert(result.message);
              this.isPlaying  = true
              this.getOrder();
              this.newOrderDto.total = result.resultObj
              // console.log(result);
            } else {
              // this.$message({message: result.message, type: 'error'});
            }
          });


    },

    selectChange(event) {
      this.selectedOption = event;
      this.query.gtype = this.selectedOption,
          // console.log(this.selectedOption),
          this.search();
    },

    selectChangeOne(e) {
      this.selectOtype = e;
      this.query.otype = this.selectOtype,
          // console.log(this.selectedOption),
      this.search();
    },

    // 一键复制方法
    copy() {
      let text = this.listData.map(item => `${item.str}`).join('\n');
      console.log("copy arguments this.message:", text);
      this.$copyText(text).then(
          function (e) {
            // console.log("copy arguments e:", e);
            // alert("复制成功!");
          },
          function (e) {
            // console.log("copy arguments e:", e);
            alert("复制失败!");
          }
      );
      this.saveFormVisible =false;

    },

    // 获取弹窗数据
    getCopys() {
      this.Loading = true;
      this.saveFormVisible = true;
      var ids = this.sels.map(item => item.id);
      // 获取选中的行
      if (!this.sels || this.sels.length < 1) {
        this.$message({message: '老铁，你未选中数据', type: 'error'});
        return;
      }
      // 通过axios调用后端分页接口
      this.$http.post("/order/SelectByIds", ids)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条

              this.Loading = false;
              this.listData = result.resultObj;
              // console.log("--------============");
              // console.log(this.listData);
            } else {
              this.$message({message: result.message, type: 'error'});
            }
          })
    },

    getCompleteByOrder(id){
      this.$http.get("/order/complete/" + id)
          .then(result => {
            result = result.data;
            if (result.success) {
              this.getOrder();
            } else {
              this.$message({message: result.message, type: 'error'});
            }
          })
    },


    getCopy(id) {
      this.$http.get("/order/SelectById/" + id)
          .then(result => {
            result = result.data;
            if (result.success) {
              this.saveFormVisible = true;
              this.listData = result.resultObj;
            } else {
              this.$message({message: result.message, type: 'error'});
            }
          })
    },

    //接单
    receiv(index, row) {
      this.$http.post("/order/" + row.id)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              // this.getCopy(row.id)
              this.listData = result.resultObj;

            } else {
              this.$message({message: result.message, type: 'error'});
            }
            this.getOrder();
          })
    },

    // 批量接单
    receiving() {
      var ids = this.sels.map(item => item.id);
      // 获取选中的行
      if (!this.sels || this.sels.length < 1) {
        this.$message({message: '老铁，你未选中数据', type: 'error'});
        return;
      }
      this.$confirm('确认接单选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.saveFormVisible =true;
        this.$http.post('/order/receivingByIds', ids).then((result) => {
          this.Loading = true;
          result = result.data;
          if (result.success) {
            // this.$message({
            //   message: result.message,
            //   type: 'success'
            // });
            this.getCopys(ids)
          } else {
            this.$message({
              message: result.message,
              type: 'error'
            });
          }
          this.getOrder();
        });
      }).catch(() => {

      });
    },

    search() {
      // 点击 查询时,应该重新从第一页开始查询
      this.query.currentPage = 1;
      this.getOrder();
    },

    handleCurrentChange(val) {
      // val 当前跳转的页码
      this.query.currentPage = val;
      this.getOrder();
    },

    handleSizeChange(val) {
      this.query.pageSize = val;
      this.query.currentPage = 1;
      //查询结果
      this.getOrder();
    },

    selsChange: function (sels) {
      this.sels = sels;
    },

    refreshBytwo(){
      this.$http.get("/order/refreshByFllow/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
      this.$http.get("/order/refreshByBaseByTall/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
    },
    refreshThree(){
      this.$http.get("/order/refreshByVideo/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
      this.$http.get("/order/refreshByBaseByp/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
      this.$http.get("/order/refreshByConmentGoos/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
    },

    // 刷新完成度接口
    refresh() {
      // 通过axios调用后端分页接口
      this.$http.get("/order/refreshByBaseByg/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
      this.$http.get("/order/refreshByBaseByf/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
      this.$http.get("/order/refreshByBaseByc/" + this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // alert("订单列表已刷新（刷新正在进行中的订单信息）")
              this.$message({message: result.message, type: 'success'});
              // this.getOrder();
            } else {
              // this.$message({message: "刷新中，请勿多次刷新页面获取数据!", type: 'error'});
            }
          });
    },


    processing(){
      this.$http.get("/order/processing/"+ this.query.accountId)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              // this.pageInfo = result.resultObj;
              // console.log("========")
              // console.log(this.pageInfo.rows)
              this.$message({message: '初始化订单进行中!', type: 'success'});
            }
          })
    },

    // 获取订单列表
    getOrder() {
      // 通过axios调用后端分页接口
      this.$http.post("/order", this.query)
          .then(result => {
            result = result.data;
            if (result.success) {
              // 要展示table的数据,渲染分页条
              this.pageInfo = result.resultObj;
              console.log("====================")
              console.log(this.pageInfo.rows)
              console.log("====================")
            } else {
              this.$message({message: result.message, type: 'error'});
            }
          })
    },

    // 退款确认
    confirmRefund(){
      this.refundFormVisible = false;
      this.merchantRefund.num = this.input;
      this.$http.post('/order/merchantRefund' ,this.merchantRefund).then((result) => {
        this.listLoading = false;
        result = result.data;
        if (result.success) {
          this.input = '';
          this.$message({
            message: "退款成功",
            type: 'success'
          });
        } else {
          this.input = '';
          this.$message({
            message: result.message,
            type: 'error'
          });
        }
        this.getOrder();
      });
    },
    getDeduction:function (index,row){

    },
    // 退款
    refund: function (index, row) {
      // this.$confirm('确认完成退款吗？', '提示', {
      //   type: 'warning'
      // }).then(() => {
        // this.listLoading = true;
        this.input = row.Completion;
        this.refundFormVisible = true;

        this.merchantRefund.oid = row.oId;

      //   this.$http.post('/order/merchantRefund' ,this.merchantRefund).then((result) => {
      //     this.listLoading = false;
      //     result = result.data;
      //     if (result.success) {
      //       this.$message({
      //         message: "退款成功",
      //         type: 'success'
      //       });
      //     } else {
      //       this.$message({
      //         message: result.message,
      //         type: 'error'
      //       });
      //     }
      //     this.getOrder();
      //   });
      // }).catch(() => {
      //
      // });
    },

    // 删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        this.$http.delete("/order/" + row.id)
            .then(result => {
              result = result.data;
              if (result.success) {
                // 操作成功:要关闭加载框 刷新当前数据  提示删除成功
                this.listLoading = false;
                // 从第一页开始重新进行查询
                this.search()
                this.$message({message: '删除成功!', type: 'success'});
              } else {
                this.$message({message: result.message, type: 'error'});
              }
            })
      }).catch(() => {
        this.$message({message: '已取消删除', type: 'info'});
      });
    },

    //显示新增界面
    handleAdd: function () {
      // 显示弹框
      this.saveFormVisible = true;
      // 将this.saveForm中的值赋空值
      this.saveForm = {
        id: null,
        key: "",
        value: "",
        intro: ""
      }
    },

    //新增/修改的保存操作
    save: function () {
      this.$refs.saveForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.addLoading = true;
            this.$http.put("/order", this.saveForm)
                .then(result => {
                  result = result.data;
                  if (result.success) {
                    // 操作成功:要关闭加载框 刷新当前数据  提示删除成功
                    this.addLoading = false;
                    // 关闭弹框
                    this.saveFormVisible = false;
                    // 从第一页开始重新进行查询
                    this.search();
                    this.$message({message: '保存成功!', type: 'success'});
                  } else {
                    this.$message({message: result.message, type: 'error'});
                  }
                })
          });
        }
      });
    },

    //批量删除
    batchRemove: function () {
      // 拿到要删除行的ID  this.sels是当前被勾选中的多选框的所有行的对象
      var ids = this.sels.map(item => item.id);
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        this.$http.patch("/order", ids)
            .then(result => {
              result = result.data;
              if (result.success) {
                // 操作成功:要关闭加载框 刷新当前数据  提示删除成功
                this.listLoading = false;
                // 从第一页开始重新进行查询
                this.search();
                this.getOrderTotal();
                this.$message({message: '删除成功!', type: 'success'});
              } else {
                this.$message({message: result.message, type: 'error'});
              }
            })
      }).catch(() => {

      });
    }

  },

  mounted() {
    this.loginAccount = JSON.parse(localStorage.getItem("loginUser"))
    this.query.accountId = this.loginAccount.id;
    this.query.type = this.loginAccount.type;
    this.newOrderDto.shopId=this.query.accountId;
    this.getOrder();
    this.refresh();
    this.refreshBytwo();
    this.refreshThree();
    this.getOrderTotal();
    // this.processing();
    // 定时任务刷新
    // this.intervalId = setInterval(() => {
    //     this.refresh();
    // }, 240000)
    // this.intervalId1 = setInterval(()=>{
    //     this.refreshBytwo();
    // },300000)
    // this.intervalId2 = setInterval(()=>{
    //   this.refreshThree();
    // },240000)

    setInterval(() => {
      // console.log(this.sels.length)
      // console.log("==============")
      if(this.sels.length < 1 ){
        // console.log("--------------")
        this.newOrder();
        if(this.isPlaying){
          this.playAudio();
          this.isPlaying = false;
        }
      }
    }, 15000)

  },


  beforeDestroy() {
    clearInterval(this.intervalId); // 清除定时器
    clearInterval(this.intervalId1); // 清除定时器
    clearInterval(this.intervalId2); // 清除定时器
  },
}

</script>

<style scoped>

</style>
